<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" type="text/css" href="markdown.css">
    <script src="https://cdn.jsdelivr.net/npm/vue@2.5.21/dist/vue.js"></script>
    <script src="https://unpkg.com/marked@0.3.6"></script>
    <script src="https://unpkg.com/lodash@4.16.0"></script>
    <title>Document</title>

</head>

<body>
    <div id="editor">
        <textarea :value="input" @input="update"></textarea>
        <div v-html="compiledMarkdown"></div>
    </div>

    <script>
        new Vue({
            el: '#editor',
            data: {
                input: '# hello world',
                date: Date.now()
            },
            computed: {
                compiledMarkdown: function () {
                    return marked(this.input, { sanitize: true })
                }
            },
            methods: {
                update: _.debounce(function (e) {
                    this.input = e.target.value
                }, 300)
            }
        })
    </script>
</body>

</html>